import { ref, computed } from 'vue'
import dayjs from 'dayjs'

export const useCountDown = () => {
  const time = ref(0)

  const formatTime = computed(()=>{
    return dayjs.unix(time.value).format('mm分ss秒')
  })

  const start = (currentTime) => {
    time.value = currentTime
    const timer = setInterval(() => {
      if (time.value <= 0) {
        clearInterval(timer)
        return
      }
      time.value--
    }, 1000)
  }

  return { formatTime, start }
}
